/*
 * ConstructEdges.java
 *
 * Created on 4 de enero de 2007, 04:10 PM
 */

package shortestPath;

/**
 *
 * @author tavobula
 */
public class ConstructEdges {
    
    private double[][] sp;
    private Edge[][] path;
    private boolean digraph;
    
    /** Creates a new instance of ConstructEdges */
    public ConstructEdges( int[][] d, boolean flag, int l) {
        digraph=flag;
        construct(d,l);
    }
    
    void construct(int[][] d, int l){
        int edgesNumber=l;
        Edge[] edges=new Edge[edgesNumber];
        int n=0;
        for(int i=0;i<d.length-1;++i){
            for(int j=i+1;j<d[i].length;++j){
                if(d[i][j]>=0){
                    edges[n]=new Edge(i,j,(d[i][j]*1d));
                    n=n+1;
                }
            }
        }
        Graph g=new Graph(d.length,digraph);
        
        for(int i=0;i<edges.length;++i){
            g.insert(edges[i]);
        }
        
        sp=new double[d.length][d.length];
        path= new Edge[d.length][d.length];
        for(int i=0;i<g.V();++i){
            GraphSPT gspt=new GraphSPT(g,i);
            for(int j=0;j<g.V();++j){
                sp[i][j]=gspt.dist(j);
                path[i][j]=gspt.pathR(j);
            }
        }
        
    }
    
    public double[][] getSP() {
        return sp;
    }
    
    public boolean isDigraph() {
        return digraph;
    }
    
    public Edge[][] getPath() {
        return path;
    }
    
}
